package com.haiberg.framework.services;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Service;

import com.haiberg.framework.dao.GenericsClassDAO;

@Service("genericsClassService")
public class GenericsClassService<T> {
	private static final Logger logger = Logger.getLogger(GenericsClassService.class);
	
	private GenericsClassDAO<T> genericsClassDAO;
	
	public int saveRecord(T aT)
	{
		try {
			return genericsClassDAO.saveRecord(aT);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("--------------save error!"+e.getMessage());
		}
		return 0;
	}
	public T findRecord(Class<T> entityClass, Serializable id)
	{
		try {
			return genericsClassDAO.findRecord(entityClass, id);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("--------------find error!"+e.getMessage());
		}
		return null;
	}
	public int deleteRecord(T aT)
	{
		try {
			return genericsClassDAO.deleteRecord(aT);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("--------------del error!"+e.getMessage());
		}
		return 0;
	}
	public int updateRecord(T aT)
	{
		try {
			return genericsClassDAO.updateRecord(aT);
		} catch (Exception e) {
			e.printStackTrace();
			logger.error("--------------update error!"+e.getMessage());
		}
		return 0;
	}
	public List<T> findAll(String hql)
	{
		try {
			return genericsClassDAO.findAll(hql);
		} catch (Exception e) {
			logger.error("--------------find all error!"+e.getMessage());
		}
		return null;
	}
	public List<T> findByCriteira(Map<String, String> criteria, String tableName)
	{
		try {
			return genericsClassDAO.findByCriteira(criteria, tableName);
		} catch (Exception e) {
			logger.error("--------------find all error!"+e.getMessage());
		}
		return null;
	}
	public GenericsClassDAO<T> getGenericsClassDAO() {
		return genericsClassDAO;
	}
	public void setGenericsClassDAO(GenericsClassDAO<T> genericsClassDAO) {
		this.genericsClassDAO = genericsClassDAO;
	}
}
